// Copyright (C) 2010 Félix Cloutier.

// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License 2.0 for more details.

// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/

#ifndef LLVM_JIT
#define LLVM_JIT

#include <llvm/LLVMContext.h>
#include <llvm/Module.h>
#include "JitRecompiler.h"
#include "JitExecutor.h"
#include "../CPUCoreBase.h"

namespace LLVMJit
{

// The main class of the LLVMJit architecture.

// Holds whatever is necessary to fulfill the CPUCoreBase interface. In itself,
//  just forwards calls to its internal components.

// Its two components, `recompiler` and `executor`, act together to perform the
//	task of recompiling and executing PPC code. While the recompiler is
//	responsible for disassembling PPC code and producing valid and tidy LLVM
//	bytecode, the executor is responsible for executing that (most likely
//	through LLVM's JIT).

// The executor is also responsible for maintaining the state of the PowerPC
//	over the execution of the program. It knows where the execution stopped and
//	where it should resume, and handles exceptions to its best.

class Jit : CPUCoreBase
{
	llvm::LLVMContext context;
	llvm::Module* currentModule;
	
	JitRecompiler* recompiler;
	JitExecutor* executor;
	
public:
	Jit();
	~Jit();

#pragma mark CPUCoreBase implementation

	virtual void Init();
	virtual void Shutdown();
	virtual void ClearCache();
	virtual void Run();
	virtual const char* GetName();
};

}

#endif